﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Logic;
using System.Xml;
using EC_DataBase;
namespace EasyCheque.MasterPages
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();
            Security.DotNetRSA.GenerateKey();
        }

        protected void Button_Welcome_Click(object sender, EventArgs e)
        {
            if (this.FileUpload_CetificateFile.HasFile)
            {
                Logic.Logic.LinkDataBase(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"\App_Data\EasyCheque.accdb"));
                Logic.Logic.m_ExceptionHandle.AlarmOn(false);
                string CerNum = Logic.Logic.LogIn(FileUpload_CetificateFile.FileContent, this.TextBox_PASSWORD.Text);
                XmlDocument XD = new XmlDocument();
                XD.LoadXml(CerNum);
                if (XD.DocumentElement.GetAttribute("Result") == "Success")
                {
                    Session["uid"] = XD.DocumentElement.InnerText;

                    EC_DataBase.Person_Info pi = EC_DataBase.OperateDB.Get_Person_Info(Convert.ToInt32(XD.DocumentElement.InnerText));
                    Session["uname"] = pi.name;
                    Session["usex"] = pi.sex;
                    Response.Redirect("~/Person/Hello_Person.aspx");
                }
                else
                {
                    Errinfo.Text = XD.DocumentElement.InnerText;
                    Panel1.Visible = true;
                }
            }
        }
    }
}
